<template>
	<!-- 公共搜索 -->
	<div>
		<TopFilter
			ref="commonTopFilter"
			:list="topFilterInit"
			:cols="3"
			labelWidth="90"
			@filterChange="changeHandle"
			@onCollapse="collapseHandle"
		></TopFilter>
	</div>
</template>
<script>
	import { dictionary } from '@/utils/dictMixin';
	import { region } from '@/api/cms-common/region';//行政区域

	export default {
		mixins: [dictionary,region],
		props:{
			defaultProjectStatusList:{
				type:Array,
				default:() => []
			}
		},
		data() {
			return {
				topFilterInit: this.topFilterInitFun(),
			};
		},
		mounted(){
			//初始化省份
			this.initProvince();
		},
		methods: {
			//初始化所在省份
			async initProvince(){
				let pl = await this.createRegionList();
				this.topFilterInit.find(item => item.fieldName === 'customerProvince' ).itemList = pl;
			},

			//搜索数据
			topFilterInitFun() {
				return [
					{ type: 'INPUT', label: '客户公司名称', fieldName: 'customerName', placeholder: '请输入', initialValue: '' },
					{ type: 'SELECT', label: '客户类型', fieldName: 'customerType', placeholder: '请选择', initialValue: '', itemList: this.createDictList('2506') },
					{ type: 'SELECT', label: '客户性质', fieldName: 'customerProperty', placeholder: '请选择', initialValue: '', itemList: this.createDictList('2534') },
					{ type: 'SELECT', label: '省份', fieldName: 'customerProvince', placeholder: '请选择', initialValue: '', itemList: []},
					{ type: 'SELECT', label: '客户状态', fieldName: 'customerStatus', placeholder: '请选择', initialValue: '', itemList: this.createDictList('2507') },
					{ type: 'SELECT', label: '客户来源', fieldName: 'customerSource', placeholder: '请选择', initialValue: '', itemList: this.createDictList('2508') },
					{ type: 'INPUT', label: '项目名称', fieldName: 'projectName', placeholder: '请输入', initialValue: '' },
					{ type: 'MULTIPLE_SELECT', label: '项目状态', fieldName: 'projectStatusList', placeholder: '请选择', initialValue: this.defaultProjectStatusList, itemList: this.createDictList('2516') },
				];
			},
			//搜索获取数据
			changeHandle(data) {
				//如果被清空了，则关联删除IDS和Names
				//防止后面更改，复制一个对象，后面的会覆盖前面的值

				let searchData = Object.assign({},data);
				if(searchData.projectStatusList.length != 0){
					searchData.projectStatuss = searchData.projectStatusList.join(',');
				}
				this.$emit('filterChange', searchData);
			},
			//展开收起
			collapseHandle() {
				this.$emit('onCollapse');
			}
		}
	};
</script>

<style lang="less" scoped>
</style>
